package com.njupt.Tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: wujiaming
 * @CreateTime: 2024/11/19 10:18
 * @Description: 二叉树中序遍历
 * @Version: 1.0
 */


public class InorderTraversal {
    public void inorder(TreeNode root,List<Integer> result){
        if(root == null) return;

        inorder(root.left,result);
        result.add(root.val);
        inorder(root.right,result);
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        inorder(root,result);

        return result;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        TreeNode node2 = new TreeNode(3);
        root.right = node1;
        node1.left = node2;

        InorderTraversal test = new InorderTraversal();
        List<Integer> list = test.inorderTraversal(root);

        System.out.println(list.toString());
    }
}
